package dame;

import java.util.Stack;

public class Test {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String str : tokens){
            if(!isfuii(str)){
                int x = Integer.parseInt(str);       //逆波兰表达式求解
                stack.push(x);
            }else{
                int val2 = stack.pop();
                int val1 = stack.pop();
                switch(str){
                    case "+":
                        stack.push(val1+val2);
                        break;
                    case "-":
                        stack.push(val1-val2);
                        break;
                    case "*":
                        stack.push(val1*val2);
                        break;
                    case "/":
                        stack.push(val1/val2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    private boolean isfuii(String ch){
        if(ch.equals("+")||ch.equals("-")||ch.equals("*")||ch.equals("/")){
            return true;
        }
        return false;
    }
    public  static  boolean IsPopOrder (int[] pushV, int[] popV) {  //出栈和入栈次序匹配
        Stack<Integer> stack  = new Stack<>();
        int j=0;
        for(int i= 0;i<pushV.length;i++){
            stack.push(pushV[i]);
            while(!stack.empty() && j<popV.length
                    && stack.peek()==pushV[i]){
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
    public static void main(String[] args) {
        MyStack myStack  =new MyStack();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
       /* myStack.push(5);
        System.out.println(myStack.peek());
        System.out.println(myStack.pop());
        System.out.println(myStack.peek());
        myStack.pop();
        myStack.pop();
        myStack.pop();
        myStack.pop();
        System.out.println(myStack.peek());*/
    }
}
